/**
 *
 */
package org.easyelf.springmvc.core.exception;

import org.apache.commons.lang3.StringUtils;
import org.easyelf.springmvc.core.support.security.HttpCode;
import org.springframework.ui.ModelMap;

/**
 * @Title: 基础异常
 * @Description: 主要用于进行异常信息的提示
 * @Package: org.easyelf.springmvc.core.base with IntelliJ IDEA
 * @User: RehngaO
 * @Date: 2017-03-13
 * @Time: 下午2:25
 */

public abstract class BaseException extends RuntimeException {

    public BaseException() {
    }

    public BaseException(Throwable ex) {
        super(ex);
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable ex) {
        super(message, ex);
    }

    public void handler(ModelMap modelMap) {
        modelMap.put("httpCode", getHttpCode().value());
        if (StringUtils.isNotBlank(getMessage())) {
            modelMap.put("msg", getMessage());
        } else {
            modelMap.put("msg", getHttpCode().msg());
        }
        modelMap.put("timestamp", System.currentTimeMillis());
    }

    protected abstract HttpCode getHttpCode();
}
